<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>

$(function(){
	//$.messager.alert("提示","已搜索完成，请查看");
	
	//$("#dialogDiv").dialog('open');
	inintHome();
	var storiedBuildingHome = '${user.getStoriedBuilding()}';
	var roleName = '${roleName}';
	
	var Mydate = new Date();
	var yyyy = Mydate.getFullYear();
	var mm = Mydate.getMonth()+1;
	var yyyymm = yyyy+"年"+mm+"月";
	var dd = Mydate.getDate();
	$("#yyyymm").html(yyyymm);
	$("#dd").html(dd);
	$("#yyyymm1").html(yyyymm);
	$("#dd1").html(dd);
});


function inintHome(){
	GetAnnouncementList();
	GetComethingLostList();
	GetComethingLostList2();
	GetMailSystemList();
}

//公告列表
function GetAnnouncementList(){
	var controlName="";
	controlName="announcementList";
	$("#"+controlName).empty().append('<h3 style="text-align: center;">正在加载数据...</h3>');
	emptyMSGAnnouncement="<li><div style='text-align:center'>暂无通知公告</div></li>";
	var storiedBuliding = $("#storiedBuilding").val();
	$.ajax({
		type:'POST',
		url:'GetAnnouncementList.action',
		data:{storiedBuliding:storiedBuliding},
		datatype:'json',
		success:function(data){
			createAnnouncementList(data,controlName,emptyMSGAnnouncement);
		}
	});
}

function createAnnouncementList(data,controlName,emptyMSG){
	 var toDoListUl = $("#"+controlName).empty();
	 if(data && data.total>0){
		 var showtips =0;
		 $.each( data.rows, function(i, theAnnouncement){
			 if(i>=5){return;}
			 var index = i+1;
			 var id = theAnnouncement.id;
			 var title = theAnnouncement.title;
			 var type = theAnnouncement.type;
			 var releaseTime = formatDate(theAnnouncement.releaseTime);//dataFormatStr(new Date(theAnnouncement.releaseTime),"yyyy-MM-dd").substring(0,7); 
			 var doIssueText = "<li class='ue-clear'><a href='showAnnouncement.action?id="+id+"' class='notice-title'>【"+type+"】"+title+"</a><div class='notice-time'>"+releaseTime+"</div></li>";
			 toDoListUl.append(doIssueText);//
		 });
	 }else{
		 toDoListUl.append(emptyMSGAnnouncement);
	 }
}

//失物招领待领
function GetComethingLostList(){
	var controlName="";
	controlName="somethingLostList";
	$("#"+controlName).empty().append('<h3 style="text-align: center;">正在加载数据...</h3>');
	emptyMSGLost="<li><div style='text-align:center'>暂无失物待领</div></li>";
	var storiedBuliding = $("#storiedBuilding").val();
	$.ajax({
		type:'POST',
		url:'GetComethingLostList.action',
		data:{status:1},
		datatype:'json',
		success:function(data){
			createComethingLostList(data,controlName,emptyMSG);
		}
	});
}

function createComethingLostList(data,controlName,emptyMSG){
	 var toDoListUl = $("#"+controlName).empty();
	 if(data && data.total>0){
		 var showtips =0;
		 $.each( data.rows, function(i, somethingLost){
			 if(i>=5){return;}
			 var index = i+1;
			 var id = somethingLost.id;
			 var title = somethingLost.title;
			 var createTime = formatDate(somethingLost.createTime);//dataFormatStr(new Date(theAnnouncement.releaseTime),"yyyy-MM-dd").substring(0,7); 
			 var time = createTime.split("-")[1];
			 var time2 = createTime.split("-")[2];
			 createTime = time+"-"+time2;
			 createTime = createTime.split(" ")[0];
			 //var doIssueText = "<li class='ue-clear'><a href='showAnnouncement.action?id="+id+"' class='notice-title'>【"+type+"】"+title+"</a><div class='notice-time'>"+releaseTime+"</div></li>";
			 doIssueText =  "<li class='ue-clear'><span class='matter-time'>"+createTime+"</span><a href='comethingLostShow.action?id="+id+"' class='matter-title'>"+title+"</a></li>"
			 //var doIssueText = "<li class='ue-clear'><a href='showAnnouncement.action?id="+id+"' class='notice-title'>"+title+"</a><div class='notice-time'>"+createTime+"</div></li>"
			 
			 toDoListUl.append(doIssueText);//
			 
			
			 
		 });
	 }else{
		 toDoListUl.append(emptyMSGLost);
	 }
}

//失物招领已领
function GetComethingLostList2(){
	var controlName="";
	controlName="somethingLostList2";
	$("#"+controlName).empty().append('<h3 style="text-align: center;">正在加载数据...</h3>');
	emptyMSGLost2="<li><div style='text-align:center'>暂无失物已领</div></li>";
	var storiedBuliding = $("#storiedBuilding").val();
	$.ajax({
		type:'POST',
		url:'GetComethingLostList.action',
		data:{status:0},
		datatype:'json',
		success:function(data){
			createComethingLostList2(data,controlName,emptyMSG);
		}
	});
}

function createComethingLostList2(data,controlName,emptyMSG){
	 var toDoListUl = $("#"+controlName).empty();
	 if(data && data.total>0){
		 var showtips =0;
		 $.each( data.rows, function(i, somethingLost){
			 if(i>=5){return;}
			 var index = i+1;
			 var id = somethingLost.id;
			 var title = somethingLost.title;
			 var createTime = formatDate(somethingLost.createTime);//dataFormatStr(new Date(theAnnouncement.releaseTime),"yyyy-MM-dd").substring(0,7); 
			 var time = createTime.split("-")[1];
			 var time2 = createTime.split("-")[2];
			 createTime = time+"-"+time2;
			 createTime = createTime.split(" ")[0];
			 //var doIssueText = "<li class='ue-clear'><a href='showAnnouncement.action?id="+id+"' class='notice-title'>【"+type+"】"+title+"</a><div class='notice-time'>"+releaseTime+"</div></li>";
			 doIssueText =  "<li class='ue-clear'><span class='matter-time'>"+createTime+"</span><a href='comethingLostShow.action?id="+id+"' class='matter-title'>"+title+"</a></li>"
			 toDoListUl.append(doIssueText);//
			 
			
			 
		 });
	 }else{
		 toDoListUl.append(emptyMSGLost2);
	 }
}

//未读邮件
function GetMailSystemList(){
	var controlName="";
	controlName="mailSystem";
	$("#"+controlName).empty().append('<h3 style="text-align: center;">正在加载数据...</h3>');
	emptyMSG="<li><div style='text-align:center'>暂无未读邮件</div></li>";
	var storiedBuliding = $("#storiedBuilding").val();
	var jStudentId = $("#studentId").val();
	$.ajax({
		type:'POST',
		url:'mailSystemList.action',
		data:{jStudentId:jStudentId},
		datatype:'json',
		success:function(data){
			createMailSystemList(data,controlName,emptyMSG);
		}
	});
}

function createMailSystemList(data,controlName,emptyMSG){
	 var toDoListUl = $("#"+controlName).empty();
	 if(data && data.total>0){
		 var showtips =0;
		 $.each( data.rows, function(i, mailSystem){
			 if(i>=5){return;}
			 var index = i+1;
			 var id = mailSystem.id;
			 var title = mailSystem.title;
			 var fCnName = mailSystem.fCnName;
			 var releaseTime = formatDate(mailSystem.time);//dataFormatStr(new Date(theAnnouncement.releaseTime),"yyyy-MM-dd").substring(0,7); 
			 var doIssueText = "<li class='ue-clear'><a href='mailSystemShow.action?id="+id+"' class='notice-title'>【"+fCnName+"】"+title+"</a><div class='notice-time'>"+releaseTime+"</div></li>";
			 toDoListUl.append(doIssueText);//
		 });
	 }else{
		 toDoListUl.append(emptyMSG);
	 }
}




function formatDate(date) {
	  var date = new Date(date);
	  var YY = date.getFullYear() + '-';
	  var MM = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
	  var DD = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
	  var hh = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
	  var mm = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
	  var ss = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
	  return YY + MM + DD +" "+hh + mm + ss;
	}


/*function opentheAnnouncement(id){
	 //$("#dialogIframe").attr("src","<c:out value='/cup/showAnnouncement.action' />?id="+id);
	 //$('#dialogDivWorkOrder').dialog('open');
	 layer.open({
         type: 2,
         title: '万年历',
         shadeClose: true,
         shade: 0.5,
         skin: 'layui-layer-rim',
//         maxmin: true,
         closeBtn:2,
         area: ['80%', '75%'],
         shadeClose: true,
         closeBtn: 2,
         content: 'showAnnouncement.action?id='+id+'',
         //iframe的url
     });
}*/